/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * OptionsSelector.java
 *
 * Created on 19 déc. 2011, 21:11:40
 */
package org.beynet.docs.ui;

import java.awt.Frame;
import java.util.ArrayList;
import org.beynet.docs.options.CommandLineOptions;

/**
 *
 * @author beynet
 */
public class OptionsSelector extends javax.swing.JDialog {

    /** Creates new form OptionsSelector */
    public OptionsSelector(Frame parent, boolean modal) {
        super(parent, modal);
        remoteCollectionsTree = new RemoteCollectionsTree(parent, true);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        chunkSizeLabel = new javax.swing.JLabel();
        chunkSize = new javax.swing.JTextField();
        validate = new javax.swing.JButton();
        destinationLabel = new javax.swing.JLabel();
        destination = new javax.swing.JTextField();
        nbThreadsLabel = new javax.swing.JLabel();
        nbThreads = new javax.swing.JTextField();
        nbThreadsLabel1 = new javax.swing.JLabel();
        statusFile = new javax.swing.JTextField();
        resume = new javax.swing.JCheckBox();
        removeDeleted = new javax.swing.JCheckBox();
        showRemoteCollections = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        chunkSizeLabel.setText("http chunk size");

        chunkSize.setColumns(5);
        chunkSize.setText("4");

        validate.setText("Validate");
        validate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                validateActionPerformed(evt);
            }
        });

        destinationLabel.setText("Destination Folder");

        destination.setColumns(20);

        nbThreadsLabel.setText("Number of Thread");

        nbThreads.setColumns(5);
        nbThreads.setText("2");

        nbThreadsLabel1.setText("Status File");

        statusFile.setColumns(5);

        resume.setText("Resume");

        removeDeleted.setText("delete remote");
        removeDeleted.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeDeletedActionPerformed(evt);
            }
        });

        showRemoteCollections.setText("Show Remotes");
        showRemoteCollections.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showRemoteCollectionsActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(20, 20, 20)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(layout.createSequentialGroup()
                                .add(nbThreadsLabel)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                .add(chunkSizeLabel)
                                .add(18, 18, 18)))
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(layout.createSequentialGroup()
                                .add(chunkSize, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(103, 103, 103))
                            .add(org.jdesktop.layout.GroupLayout.LEADING, nbThreads, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(layout.createSequentialGroup()
                        .add(39, 39, 39)
                        .add(resume)
                        .add(35, 35, 35)
                        .add(removeDeleted)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)))
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(validate)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(destinationLabel)
                            .add(nbThreadsLabel1))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(statusFile)
                            .add(destination))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(showRemoteCollections)))
                .addContainerGap(53, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(32, 32, 32)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(chunkSize, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(chunkSizeLabel)
                    .add(destinationLabel)
                    .add(destination, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(showRemoteCollections))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(nbThreadsLabel)
                    .add(nbThreads, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(nbThreadsLabel1)
                    .add(statusFile, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 25, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(validate)
                    .add(resume)
                    .add(removeDeleted))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    
public String[] getOptions() {
    ArrayList<String> options = new ArrayList<String>();
    if (chunkSize.getText()!=null && !"".equals(chunkSize.getText())) {
        options.add(CommandLineOptions.OPTION_HTTP_CHUNK_SIZE);
        options.add(chunkSize.getText());
    }
    if (destination.getText()!=null && !"".equals(destination.getText())) {
        options.add(CommandLineOptions.OPTION_DESTINATION);
        options.add(destination.getText());
    }
    if (nbThreads.getText()!=null && !"".equals(nbThreads.getText())) {
        options.add(CommandLineOptions.OPTION_MAX_UPLOAD_THREADS);
        options.add(nbThreads.getText());
    }
    if (statusFile.getText()!=null && !"".equals(statusFile.getText())) {
        options.add(CommandLineOptions.OPTION_STATUSFILE);
        options.add(statusFile.getText());
    }
    if (resume.isSelected()) {
        options.add(CommandLineOptions.OPTION_RESUME);
    }
    if (removeDeleted.isSelected()) {
        options.add(CommandLineOptions.OPTION_DELETE);
    }
    String[] res = new String[options.size()];
    for (int i=0;i<options.size();i++) {
        res[i] = options.get(i);
    }
    return(res);
}
    
private void validateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_validateActionPerformed
    this.setVisible(false);
}//GEN-LAST:event_validateActionPerformed

    private void removeDeletedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeDeletedActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_removeDeletedActionPerformed

    private void showRemoteCollectionsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showRemoteCollectionsActionPerformed
        // TODO add your handling code here:
        remoteCollectionsTree.setVisible(true);
        String path = remoteCollectionsTree.getSelectedPath();
        if (path!=null) {
            destination.setText(path);
        }
    }//GEN-LAST:event_showRemoteCollectionsActionPerformed

    private RemoteCollectionsTree remoteCollectionsTree ;
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField chunkSize;
    private javax.swing.JLabel chunkSizeLabel;
    private javax.swing.JTextField destination;
    private javax.swing.JLabel destinationLabel;
    private javax.swing.JTextField nbThreads;
    private javax.swing.JLabel nbThreadsLabel;
    private javax.swing.JLabel nbThreadsLabel1;
    private javax.swing.JCheckBox removeDeleted;
    private javax.swing.JCheckBox resume;
    private javax.swing.JButton showRemoteCollections;
    private javax.swing.JTextField statusFile;
    private javax.swing.JButton validate;
    // End of variables declaration//GEN-END:variables
}
